[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
OPERATORS
The following table lists the operators available in SALT:
Symbol (Un/Bin)ary What it is/does
- unary Arithmetic negation
-- unary Decrement variable by 1
++ unary Increment variable by 1
! unary Logical NOT
not unary Logical NOT (alternate)
* binary Multiplication
/ binary Division
% binary Remainder (Mod)
+ binary Addition
- binary Subtraction
< binary Less than
> binary Greater than
<= binary Less than or equal to
>= binary Greater than or equal to
== binary Equality
!= binary Inequality
& binary Bitwise AND
| binary Bitwise OR
^ binary Bitwise Exclusive OR
&& binary Logical AND
and binary Logical AND (alternate)
|| binary Logical OR
or binary Logical OR (alternate)
= binary Assignment
Note that the hyphen symbol can be either an arithmetic negation or
a subtraction depending on its use. Note that '!' is equivalent to
'not', '&&' is equivalent to 'and', and '||' is equivalent to 'or'.
The first form is preferred as you do not have to leave whitespace
around it for the compiler to recognize it, but beginners may have
an easier time remembering the second form. Also, do not confuse the
'=' (assignment operator) with the '==' (equality operator). The
former is used to assign a value to a variable, while the latter is
used to compare two values. Assuming you have the two expressions,
<expr1> and <expr2>, <expr1> = <expr2> would assign one to the
other, while <expr1> == <expr2> would test the two to see if they
are equal. For example
num = 10
would assign the value 10 to the variable called 'num', while
num == 10
would resolve to a value of non-zero (TRUE) if num was equal to 10,
and 0 (FALSE) if num was not equal to 10. There is also a difference
between the Logical operators and the Bitwise operators. The Logical
operators (such as and, &&, or, ||, etc), work with TRUE or FALSE
values and result in a TRUE or FALSE value, while the Bitwise opera-
tors (&, |, ^) work with the actual bits of the data they are han-
dling. The Bitwise operators almost never have to be used in a Telix
script, unless it is needed to get at the actual bits in a data
byte.
Every operator resolves to a value, which is the result of the
operation performed (e.g, 10 * 7 would resolve to 70). The condi-
tional or equality operators such as ==, >, <=, etc., resolve to a
0 (FALSE)) or non-zero (TRUE) value based on the results of the ex-
pression. Even the assignment operator = resolves to a value. The
result of the expression
num = 10
would be 10.
All the operators have something called precedence, which is their
importance, and determines the order in which they are evaluated.
For example, 7 + 3 * 9 is equal to 34, because 3 * 9 is evaluated
first, and then added to 7 (* has a higher precedence than +). All
the operators are listed below in order of decreasing precedence.
All the operators on the same line have the same precedence, and are
resolved in the order that they are encountered.
- !
* / %
+ -
< > <= >=
== !=
&
|
and &&
or ||
=
If a certain evaluation order is required that does not follow these
rules of precedence, parentheses may be used. Thus, 99 + 1 * 10
equals 109, while (99 + 1) * 10 equals 1000.
If you are writing an expression of any sort, and are not sure of
the exact precedence of the operators you are using, use paren-
theses!
See Also:
expressions
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson